package com.lamatek.tags.google;

import java.io.Serializable;
import java.util.Vector;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * GoogleMapMarkerTag
 * 
 * This class represents a &lt;googlemaps:marker> tag. Developers should not subclass or override this
 * class or it's methods.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapMarkerTag extends BodyTagSupport implements Serializable, GoogleMapEventListener {

    String id = null;
    String point = null;
    InfoWindow infoWindow = null;
    GoogleMapBlowupTag blowup = null;
    Vector events = null;
    GoogleMapIconTag icon = null;
    boolean draggable = false;
    /**
     * Overrides doStartTag() from BodytagSupport. Developers should not override this method.
     */
    public int doStartTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).addMarker(this);
                return EVAL_BODY_INCLUDE;
            }
            tag = tag.getParent();
        }
        return EVAL_BODY_INCLUDE;
    }
    /**
     * Overrides doStartTag() from BodytagSupport. Developers should not override this method.
     */
    public int doEndTag() {
        return EVAL_PAGE;
    }
    /**
     * Adds an event to this marker. Only events of type 'click' or 'dblclick' will actually
     * register.
     * 
     * @param event An initializes GoogleMapEventTag
     */
    public void addEvent(GoogleMapEventTag event) {
        if (events == null)
            events = new Vector();
        events.add(event);
    }
    /**
     * Sets the info window for this marker. There can only be one info window per marker, so
     * successive calls to this method will remove the previous info window, replacing it with the
     * current one.
     * 
     * @param infoWindow A tag that implements InfoWindow
     */
    public void setInfoWindow(InfoWindow infoWindow) {
        this.infoWindow = infoWindow;
    }
    /**
     * Sets the map blowup window for this marker. There can only be one blowup window per marker, so
     * successive calls to this method will remove the previous blowup window, replacing it with the
     * current one.
     * 
     * @param infoWindow An initialized GoogleMapBlowupTag
     */
    public void setBlowup(GoogleMapBlowupTag blowup) {
        this.blowup = blowup;
    }
    /**
     * Sets a GoogleMapIconTag for this marker, overriding the standard Google Maps marker icon.
     * 
     * @param icon An initialized GoogleMapIconTag
     */
    public void setIcon(GoogleMapIconTag icon) {
        this.icon = icon;
    }
    /**
     * Returns the currently defined info window for this marker.
     * 
     * @return A GoogleMapInfoWindowTag
     */
    public InfoWindow getInfoWindow() {
        return infoWindow;
    }
    /**
     * Returns the currently defined blowup window for this marker.
     * 
     * @return A GoogleMapBlowupTag
     */
    public GoogleMapBlowupTag getBlowup() {
        return blowup;
    }
    /**
     * Returns this marker's id.
     * 
     * @return A String representing the marker's id.
     */
    public String getId() {
        return id;
    }
    /**
     * Sets the unique id for this marker.
     * 
     * @param id A unique id for this marker instance.
     */
    public void setId(String id) {
        this.id = id;
    }
    /**
     * Returns the id of the GoogleMapPointTag used as the centerpoint
     * for this marker.
     * 
     * @return A GoogleMapPointTag id.
     */
    public String getPoint() {
        return point;
    }
    /**
     * Sets the id for the GoogleMapPointTag used as the centerpoing for 
     * this marker.
     * 
     * @param point A valid GoogleMapPointTag id.
     */
    public void setPoint(String point) {
        this.point = point;
    }
    /**
     * Returns the list of currently registered event listeners
     * for this overlay.
     * 
     * @return A Vector of GoogleMapEventTags
     */
    public Vector getEvents() {
        return events;
    }
    /**
     * Sets a list of registered event listeners.
     * 
     * @param events A Vector of GoogleMapEventTags.
     */
    public void setEvents(Vector events) {
        this.events = events;
    }
    /**
     * Returns the GoogleMapIconTag that renders this marker, or null if the default
     * markers are used.
     * 
     * @return A GoogleMapIconTag or null.
     */
    public GoogleMapIconTag getIcon() {
        return icon;
    }
    /**
     * Denotes whether or not this marker should be draggable.
     * 
     * @return True if this marker is draggable. False if not.
     */
    public boolean isDraggable() {
        return draggable;
    }
    /**
     * Sets wheter or not this marker should be draggable.
     * Default is false.
     * 
     * @param draggable True if this marker is to be draggable, false if not.
     */
    public void setDraggable(boolean draggable) {
        this.draggable = draggable;
    }
}
